<template>
  <el-input
    v-bind="{ ...$props, ...$attrs }"
    :formatter="(value: string) => `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
    :parser="(value: string) => value.replace(/\$\s?|(,*)/g, '')"
    placeholder="请输入金额"
    @input="(value: any) => $emit('update:modelValue', value.replace(/[^0-9][.][^0-9]/g, ''))"
  >
    <template #append>{{ unit }}</template>
  </el-input>
</template>
<script lang="ts" setup>
defineEmits(["update:modelValue"]);
const props = defineProps({
  unit: {
    type: String,
    default: "元",
  },
});
const unit = ref(props.unit);
</script>
<style lang="scss" scoped></style>
